#!/usr/bin/python
#coding=utf-8
import os
import sys
if __name__ == '__main__':
    size=len(sys.argv)
    if int(size) < 4:
        raise Exception('args size lt 4')
    file=open(sys.argv[1],'rb')
    newFileName=os.path.basename(sys.argv[1])
    newFilePath=os.path.dirname(sys.argv[1])
    if newFilePath == None or cmp(newFilePath,'')==0:
        newFilePath = './'
    else:
        newFilePath=newFilePath+"/"
    newFile=open(newFilePath+'new_'+newFileName,'wb')
    for line in file.readlines():
        dec=line.decode(sys.argv[2])
        enc=dec.encode(sys.argv[3])
        newFile.writelines(enc)
    file.close()
    newFile.close()
